﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>菜单权限设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
</head>
<body>
    <div style="margin:10px;padding:5px">
        <xblock>
            <button class="layui-btn" onclick="saveUserGongXu()"><i class="layui-icon"></i>保存</button>
            <button class="layui-btn" onclick="closeWin()"><i class="layui-icon">&#x1006;</i>取消</button>
        </xblock>
        <input type="hidden" name="powers" />
        <form class="layui-form layui-col-space5">
            <div id="gxInfo" style="margin-top:15px">
            </div>
        </form>
        <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
            <table class="layui-hide" id="list" lay-filter="list"></table>
        </div>    
</div>
</body>
</html>
<script type="text/javascript">
    var usCode = "";
    var userCode = "";

    $(function () {
        usCode = getUrlVariable('userCode');
        userCode = decodeURI(usCode);

        loadGongXu();
 
        //layui.use('form', function () {
        //    var form = layui.form;
        //    form.render();
        //});
    })

    function loadGongXu() {
        //var condition = null;
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#list'
                , cols: [[ //标题栏
                      { type: 'checkbox' }
                    , { field: 'gxCode', title: '工序编码', width: 110 }
                    , { field: 'gxName', title: '工序名称', width: 120 }
                    , { field: 'orderNum', title: '工序序号', width: 90, edit: 'text' }
                ]], done: function (res, curr, count) {
                    $.each(res['data'], function (i, j) {
                        if (j["cgx"] == "1") {
                            j["LAY_CHECKED"] = 'true';
                            var index = j['LAY_TABLE_INDEX'];
                            $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                            $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                        }
                    });
                }
                //, url: '../ProductSet/GetDataList?dataType=gxd&condition=' + condition
                , url: '../Basis/GetDataList?dataType=pgx&condition=' + userCode
                , skin: 'row' //表格风格
                , even: true
                , page: false //是否显示分页
                , limits: [20, 35, 50]
                , limit: 20 //每页默认显示的数量
            });
        });
    }
    //function loadGongXu() {
    //    $.ajax({
    //        url: "../Basis/GetCommonData",
    //        data: { type: "Gx" },
    //        dataType: "json",
    //        type: "POST",
    //        async: false,
    //        success: function (data) {
    //            if (data.Result) {
    //                var datas = data.Data;
    //                var ps = "";
    //                for (var i = 0 ; i < datas.length; i++) {
    //                    var title = datas[i].cName + "(" + datas[i].cCode + ")";
    //                    ps += "<input lay-skin='primary' type='checkbox'  value='" + datas[i].cCode + "'  title='" + title + "'  name='checkop'/>";

    //                }
    //                $("#gxInfo").append(ps);
    //                userGongXu();

                

    //            }

    //        }
    //    });
    //}

    /**
    获取人员关联工序
    **/
    //function userGongXu() {
    //    $.ajax({
    //        url: "../Basis/getUserGongXu",
    //        data: { userCode: usCode },
    //        dataType: "json",
    //        type: "POST",
    //        async: false,
    //        success: function (data) {
    //            if (data.Result) {
    //                var datas = data.Data;
    //                    SetCheckBoxValue("checkop", datas);
    //            }

    //        }
    //    });
    //}


    /** 保存权限信息 **/
    //function saveUserGongXu() {
    //    try {
    //        var vstr = "";
    //        $("input[type=checkbox][name=checkop]:checked").each(function () { //由于复选框一般选中的是多个,所以可以循环输出
    //            vstr += $(this).val() + ",";
    //        });
    //        vstr = vstr.slice(0, -1);
    //        $.ajax({
    //            url: "../Basis/SaveUserGongXu",
    //            data: { userCode: usCode, gxCodes: vstr },
    //            dataType: "json",
    //            type: "POST",
    //            success: function (data) {
    //                if (data.Result) {
    //                    layer.alert("保存成功", { icon: 6 }, function () {
    //                        // 获得frame索引
    //                        var index = parent.layer.getFrameIndex(window.name);
    //                        //关闭当前frame
    //                        parent.layer.close(index);
    //                    });
    //                } else {
    //                    layer.msg(data.Message);
    //                }
    //            }
    //        });
    //    } catch (e) {
    //        window.location = "/Error/Error";
    //    }
    //}
    function saveUserGongXu() {
        try{
            var checkStatus = layui.table.checkStatus('list').data;
            var gxStr = [];

            for (var i = 0; i < checkStatus.length; i++) {

                gxStr.push(checkStatus[i].gxCode + "-" + checkStatus[i].orderNum);
            }
            gxStr = gxStr.join(',');//必须要写，不然后台获取不到数据
            //alert(gxStr + "        " + userCode);

            $.ajax({
                url:'../Basis/SaveUserGongXu',
                data: { userCode: userCode, gxCodes: gxStr },
                dataType: "json",
                type: "POST",
                success: function (data) {
                    if (data.Result) {
                        //var id = $("input[ name='id']").val();
                        var msg = "数据保存成功";

                        layer.alert(msg, { icon: 6 }, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(data.Message);
                    }
                }
            });
        }catch(e){
            layer.msg(e.message);
        }
      
    }
</script>
